package com.apes.enquiry.supplier.baturu.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.jpa.tuple.date.DateTime;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = BaturuInquireResult.CONST_TABLE_NAME)
public class BaturuInquireResult extends BaseModel {
    public static final String CONST_TABLE_NAME = "sp_buturu_inquire_result";

    @Id
    @Column(name = "id", length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "巴图鲁-询价结果")
    @Comment("编号")
    private String id;

    @Comment("询价明细编码")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "baturu_inquire_item_id", referencedColumnName = "id")
    private BaturuInquireItem baturuInquireItem;


    @Comment("客服修正后的配件名称")
    @Column(name = "modified_parts_name")
    private String modifiedPartsName;

    @Comment("配件编码")
    @Column(name = "quoted_parts_code", length = 60)
    private String quotedPartsCode;

    @Comment("配件报价状态") //	1：报价中；2：已报价；3：已打回；4：已失效。
    @Column(name = "quote_status")
    private int quoteStatus;

    @Comment("客服打回原因")
    @Column(name = "beat_back_reason")
    private String beatBackReason;

    @Comment("配件备注")
    @Column(name = "remark")
    private String remark;

    @OneToMany(mappedBy = "baturuInquireResult", cascade = CascadeType.ALL, orphanRemoval = true)
    private Set<BaturuInquireSupplier> baturuInquireSuppliers = new HashSet<>();
    public Set<BaturuInquireSupplier> getBaturuInquireSuppliers() {
//        for (BaturuInquireSupplier item:baturuInquireSuppliers) {
//            item.setBaturuInquireResult(this);
//        }
        return baturuInquireSuppliers;
    }



}
